<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateCouponTable extends Migrator
{
    public function up()
    {
        $sql = <<<SQL
CREATE TABLE `coupon_brand` (
  `id` int PRIMARY KEY AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT "" COMMENT '品牌名',
  `image_url` varchar(800) DEFAULT "" COMMENT '品牌logo',
  `cate_id` varchar(50) NOT NULL DEFAULT "" COMMENT '分类',
  `status` tinyint DEFAULT 1 COMMENT '状态(1:启用,0:关闭)',
  `sort` int DEFAULT 0 COMMENT '排序',
  `mark` varchar(300) NOT NULL DEFAULT "" COMMENT '导入聚推客使用匹配',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间'
);

CREATE TABLE `coupon_cate` (
  `id` int PRIMARY KEY AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT "" COMMENT '分类名称',
  `status` tinyint DEFAULT 1 COMMENT '状态(1:启用,0:关闭)',
  `sort` int DEFAULT 0 COMMENT '排序',
  `mark` varchar(50) NOT NULL DEFAULT "" COMMENT '导入聚推客使用匹配，上线后可删除',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间'
);

CREATE TABLE `coupon_brand_cate_relation` (
  `cate_id` int DEFAULT 0 COMMENT '分类id',
  `brand_id` int DEFAULT 0 COMMENT '品牌id'
);

CREATE TABLE `coupon_product` (
  `id` int PRIMARY KEY AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT "" COMMENT '权益产品',
  `brand_id` int DEFAULT 0 COMMENT '品牌',
  `status` tinyint DEFAULT 1 COMMENT '状态(1:启用,0:关闭)',
  `sort` int DEFAULT 0 COMMENT '排序',
  `mark` varchar(50) NOT NULL DEFAULT "" COMMENT '导入聚推客使用匹配',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间'
);

CREATE TABLE `coupon_product_channel` (
  `id` int PRIMARY KEY AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT "" COMMENT '产品渠道',
  `supplier_id` int DEFAULT 0 COMMENT '供应商',
  `origin_id` varchar(50) NOT NULL DEFAULT "" COMMENT '第三方id',
  `product_id` int DEFAULT 0 COMMENT '产品id',
  `sale_price` int DEFAULT 0 COMMENT '销售价',
  `cost_price` int DEFAULT 0 COMMENT '成本价',
  `market_price` int DEFAULT 0 COMMENT '市场价',
  `extend` text COMMENT '扩展字段存json',
  `rule` text COMMENT '规则说明',
  `status` tinyint DEFAULT 1 COMMENT '状态(1:启用,2:关闭)',
  `mark` varchar(50) NOT NULL DEFAULT "" COMMENT '导入聚推客使用匹配',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间'
);

SQL;

        $this->execute($sql);

    }
    public function down()
    {
        $this->dropTable('coupon_brand');
        $this->dropTable('coupon_cate');
        $this->dropTable('coupon_brand_cate_relation');
        $this->dropTable('coupon_product');
        $this->dropTable('coupon_product_channel');
    }
}
